﻿Public Class FrmBuscarArticulos
    Dim combo As New combo
    Dim acceso As New acceso_a_datos
    Dim frmABMArticulo As FrmABMArticulo
    Public Sub New(ByRef frmABMArticulo As FrmABMArticulo)
        InitializeComponent()
        Me.frmABMArticulo = frmABMArticulo
    End Sub

    Private Sub cmbCategoria_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbCategoria.SelectedIndexChanged
        Select Case cmbCategoria.SelectedIndex
            Case 0
                Me.txtTextoABuscar.Enabled = True
                Me.cmbFiltro.Enabled = False
                btnBuscar.Enabled = True
            Case 1
                Me.cmbFiltro.Enabled = True
                Me.combo.cadena_conexion = acceso._CadenaConexion
                Me.combo.cargar(Me.cmbFiltro, "Genero")
            Case 2
                Me.cmbFiltro.Enabled = True
                Me.combo.cadena_conexion = acceso._CadenaConexion
                Me.combo.cargar(Me.cmbFiltro, "Calificacion")
            Case 3
                Me.cmbFiltro.Enabled = True
                Me.combo.cadena_conexion = acceso._CadenaConexion
                Me.combo.cargar(Me.cmbFiltro, "TipoArticulo")
        End Select
    End Sub
    Private Sub cmbFiltro_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbFiltro.SelectedIndexChanged
        txtTextoABuscar.Enabled = True
        btnBuscar.Enabled = True
    End Sub

    Private Sub btnBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscar.Click
        acceso._tabla = "Articulo"
        Dim consulta As String = "SELECT a.idarticulo ,a.codigoBarras as 'Código de Barras', a.nombre as 'Nombre', a.sinopsis as 'Sinopsis', t.Descripcion as 'Tipo de Artículo', c.descripcion as 'Calificación', g.descripcion as 'Genero', a.cantidadAlquiler as 'Cantidad Alquiler', a.cantidadVenta as 'Cantidad Venta' FROM Articulo a, Genero g, TipoArticulo t, Calificacion c WHERE a.idTipoArticulo=t.idTipoArticulo AND a.idGenero=g.idGenero AND a.idCalificacion= c.idCalificacion AND a.nombre like '%" & txtTextoABuscar.Text & "%'"
        Select Case cmbCategoria.SelectedIndex
            Case 1
                consulta += " AND a.idGenero =" & cmbFiltro.SelectedValue
            Case 2
                consulta += " AND a.idCalificacion =" & cmbFiltro.SelectedValue
            Case 3
                consulta += " AND a.idTipoArticulo =" & cmbFiltro.SelectedValue
        End Select
        Dim tabla As Data.DataTable = acceso._consulta(consulta)
        frmABMArticulo.resultadoBusqueda(tabla)
        Me.Close()
    End Sub

    Private Sub FrmBuscarArticulos_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class
